package com.qqhf.hitfood.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.qqhf.common.entity.AjaxResult;
import com.qqhf.common.entity.PageEntity;
import com.qqhf.hitfood.bean.core.BaseController;
import com.qqhf.hitfood.bean.entity.TypeFood;
import com.qqhf.hitfood.service.ITypeFoodService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;

@Api(tags = "T - [字典]食品分类")
@RestController
@RequestMapping("/type/food")
public class TypeFoodController extends BaseController {
    @Autowired
    private ITypeFoodService typeFoodService;

    @GetMapping("/page")
    public AjaxResult page(PageEntity pageEntity, TypeFood typeFood) {
        return AjaxResult.success(typeFoodService.page(pageEntity.toPage(), Wrappers.lambdaQuery(typeFood)));
    }

    @GetMapping("/list")
    public AjaxResult list(TypeFood typeFood) {
        return AjaxResult.success(typeFoodService.list(Wrappers.lambdaQuery(typeFood)));
    }

    @PostMapping("/add")
    public AjaxResult add(@RequestBody TypeFood typeFood) {
        return AjaxResult.success(typeFoodService.save(typeFood));
    }

    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody TypeFood typeFood) {
        return AjaxResult.success(typeFoodService.updateById(typeFood));
    }

    @DeleteMapping("/delete/{ids}")
    public AjaxResult delete(@PathVariable Integer[] ids) {
        return AjaxResult.success(typeFoodService.removeByIds(Arrays.asList(ids)));
    }

    @GetMapping(value = "/detail/{id}")
    public AjaxResult detail(@PathVariable("id") Integer id) {
        return AjaxResult.success(typeFoodService.getById(id));
    }
}
